/**
 * 背景层
 */
define(['createjs'],function(createjs){
	var BGLayer = function(layer,width,height){
		this._layer = layer;
		this._width = width;
		this._height = height;
		this._bgImg = false;
		
		//白底
		this.whiteBg = new createjs.Shape();
		this.whiteBg.graphics.beginFill("#FFFFFF").drawRect(0,0,this._width,this._height);
		this._layer.addChild(this.whiteBg);

		/**
		 * 画画
		 * @param {Object} imageObj 要画的对象
		 */
		this.draw = function(imageObj){
			if(this._bgImg)
				this._layer.removeChild (this._bgImg);
				
			this._bgImg = new createjs.Bitmap(imageObj.imageObj);
			this._bgImg.set({
				x:imageObj.x,
				y:imageObj.y,
				scaleX : imageObj.width/imageObj.imageObj.width,
				scaleY : imageObj.height/imageObj.imageObj.height
			});
			this._layer.addChild(this._bgImg);
		}
		
		/**
		 * 清空
		 */
		this.clear = function(){
			this._layer.removeChild (this._bgImg);
		}
		
		/**
		 * 得到背景图
		 */
		this.getBg = function(){
			return this._bgImg;
		}
		
		/**
		 * 设置背景图
		 * @param {createjs.Bitmap} bitmap 要设置的bitmap
		 */
		this.setBg = function(bitmap){
			if(this._bgImg)
				this._layer.removeChild (this._bgImg);
				
			this._bgImg = bitmap.clone();
			this._layer.addChild(this._bgImg);
		}
		
	};
	
	return BGLayer;
});